<?php
/**
 * //w/w/w.s/h/u/o/t//u/p/u c/o/m  说/图/谱/源/码/分/享
 */
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/26 0026
 * Time: 下午 2:30
 */
defined("IN_IA")or exit("Access Denied");
checklogin();  //验证是否登录
global $_W,$_GPC;
$uniacid=$_W['uniacid'];
$op=$_GPC['op'] ? $_GPC['op'] : "live_type";

//直播分类列表
if($op=='live_type'){

    $condition=array();
    $condition['uniacid']=$uniacid;
    $listCount=pdo_getall("cqkundian_farm_live_type",$condition);
    $total=count($listCount);   //数据的总条数
    $pageSize=10; //每页显示的数据条数
    $pageIndex=intval($_GPC['page']) ? intval($_GPC['page']) :1;  //当前页
    $pager=pagination($total,$pageIndex,$pageSize);
    $list=pdo_getall("cqkundian_farm_live_type",$condition,'','','rank asc',array($pageIndex,$pageSize));
    include $this->template("web/live/index");
}

if($op=='live_type_edit'){
    if($_GPC['id']){
        $list=pdo_get('cqkundian_farm_live_type',array('id'=>$_GPC['id'],'uniacid'=>$uniacid));
    }
    include $this->template("web/live/edit");
}

//直播分类保存
if($op=='live_type_save'){
    $data=array(
        'name'=>$_GPC['name'],
        'status'=>$_GPC['status'],
        'rank'=>$_GPC['rank'],
        'uniacid'=>$uniacid,
    );
    if(empty($_GPC['id'])){  //新增
        $request=pdo_insert("cqkundian_farm_live_type",$data);
    }else{
        $condition=array(
            'id'=>$_GPC['id'],
            'uniacid'=>$uniacid,
        );
        $request=pdo_update("cqkundian_farm_live_type",$data,$condition);
    }
    if($request){
        message("操作成功",$this->createWebUrl("live"));
    }else {
        message("操作失败", '', 'warning');
    }
}

//直播分类状态修改
if($op=='statusChange'){
    $id=$_GPC['id'];
    $res=pdo_update('cqkundian_farm_live_type',array('status'=>$_GPC['status']),array('id'=>$id,'uniacid'=>$uniacid));
    echo $res ? json_encode(array('status'=>1)) : json_encode(array('status'=>2));die;
}

//直播分类删除
if($op=='delete_live_type'){
    $id=$_GPC['id'];
    $res=pdo_delete('cqkundian_farm_live_type',array('id'=>$id,'uniacid'=>$uniacid));
    echo $res ? json_encode(array('status'=>1)) : json_encode(array('status'=>2));die;
}

//直播列表
if($op=='live_list'){
    $condition=array();
    $condition['uniacid']=$uniacid;
    $listCount=pdo_getall("cqkundian_farm_live",$condition);
    $total=count($listCount);   //数据的总条数
    $pageSize=16; //每页显示的数据条数
    $pageIndex=intval($_GPC['page']) ? intval($_GPC['page']) :1;  //当前页
    $pager=pagination($total,$pageIndex,$pageSize);
    $list=pdo_getall("cqkundian_farm_live",$condition,'','','rank asc',array($pageIndex,$pageSize));
    for($i=0;$i<count($list);$i++){
        $type=pdo_get('cqkundian_farm_live_type',array('id'=>$list[$i]['type_id'],'uniacid'=>$uniacid));
        $list[$i]['name']=$type['name'];
    }
    include $this->template("web/live/live_list");
}

//直播编辑
if($op=='live_edit'){
    $typeData=pdo_getall('cqkundian_farm_live_type',array('uniacid'=>$uniacid,'status'=>1));
    if($_GPC['id']){
        $list=pdo_get('cqkundian_farm_live',array('id'=>$_GPC['id'],'uniacid'=>$uniacid));
    }
    include $this->template("web/live/live_edit");
}

//直播保存
if($op=='live_save'){
    $data=array(
        'src'=>$_GPC['src'],
        'cover'=>tomedia($_GPC['cover']),
        'title'=>$_GPC['title'],
        'rank'=>$_GPC['rank'],
        'type_id'=>$_GPC['type_id'],
        'status'=>$_GPC['status'],
        'uniacid'=>$uniacid,
    );
    if(empty($_GPC['id'])){  //新增
        $request=pdo_insert("cqkundian_farm_live",$data);
    }else{
        $condition=array(
            'id'=>$_GPC['id'],
            'uniacid'=>$uniacid,
        );
        $request=pdo_update("cqkundian_farm_live",$data,$condition);
    }
    if($request){
        message("操作成功",url("site/entry/live",array('m'=>'kundian_farm','op'=>'live_list')));
    }else {
        message("操作失败", '', 'warning');
    }
}

//直播分类删除
if($op=='delete_live'){
    $id=$_GPC['id'];
    $res=pdo_delete('cqkundian_farm_live',array('id'=>$id,'uniacid'=>$uniacid));
    echo $res ? json_encode(array('status'=>1)) : json_encode(array('status'=>2));die;
}






